#include "post.h"

char fpath[PATH_LENGTH+NAME_LENGTH+1]; //for '\0'

int setPath() {
  strcpy(fpath, "../posts/");
  return 0;
}

int getPostDate() {
  time_t now;
  struct tm* T;
  now = time(NULL);
  T = localtime(&now);

  strftime(&fpath[PATH_LENGTH], NAME_LENGTH+1, "%Y%m%d.txt", T);
  return 0;
}

int writePost() {
  FILE* post;
  post = fopen(fpath, "w");
  if (post) {
    fprintf(post, "Thank you for using gnoui. Start by writing your very own post in the posts directory!");
    fclose(post);
    return 0;
  }
  return 1;
}

int main() {
  setPath();
  getPostDate();
  writePost();
  return 0;
}
